package com.mepo.cheer.client;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mepo.cheer.client.pages.HomePage;
import com.mepo.cheer.shared.MepoMenuType;

public class MepoCheerTempate {
	
	private static VerticalPanel contentPanel = new VerticalPanel();
	private static HorizontalPanel horizontalPanel = new HorizontalPanel();
	
	private static final DataServiceAsync dsa = GWT.create(DataService.class);
	
	public static void createTemplate() {
		horizontalPanel.setStyleName("orangeBanner");
		horizontalPanel.setWidth("100%");
		
		Label headerLabel = new Label("Mediapolis Cheerleading");
		headerLabel.addClickHandler(homeClickHandler);
		headerLabel.setStyleName("cheerHeader");
		headerLabel.setWordWrap(false);
		horizontalPanel.add(headerLabel);
		
		dsa.getMenuItems(new AsyncCallback<List<List<MepoMenuType>>>() {
			@Override
			public void onSuccess(List<List<MepoMenuType>> result) {
				MenuBar menu = new MenuBar(false);
				menu.setStyleName("cheerMenu");
				for(List<MepoMenuType> submen : result) {
					MenuBar bar = new MenuBar(true);
					MenuItem item = new MenuItem(submen.get(0).getMenuCategory(), false, bar);
					item.setStyleName("mepo-menu-item");
					menu.addItem(item);
					for(MepoMenuType menuItem : submen) {
						MenuItem subItem = new MenuItem(menuItem.getMenuText(), false, menuItem.getOnClickCommand());
						bar.addItem(subItem);
					}
				}

				horizontalPanel.add(menu);
				horizontalPanel.setCellVerticalAlignment(menu, HasVerticalAlignment.ALIGN_BOTTOM);
				horizontalPanel.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
			}
			
			@Override
			public void onFailure(Throwable caught) {
				Window.alert("Error connecting to server");				
			}
		});
		

		contentPanel.setSize("100%", "100%");
		contentPanel.add(horizontalPanel);
		contentPanel.add(new Label());

		RootPanel rootPanel = RootPanel.get("content");
		RootPanel.get().setStyleName("template-background");
		rootPanel.clear();
		rootPanel.add(contentPanel);
	}
	
//	private static MenuBar createMenu() {
		
		
		
		
		
//		//TODO: css make text font = "Ebrima"
//		//MenuBar
//		MenuBar squadsBar = new MenuBar(true);
//		MenuBar mediaBar = new MenuBar(true);
//		MenuBar coachesBar = new MenuBar(true);
//		
//		//Squads
//		MenuItem mntmSquads = new MenuItem("Squads", false, squadsBar);
//		mntmSquads.setStyleName("mepo-menu-item");
//		
//		MenuItem mntmFotball = new MenuItem("Football", false, footballCommand);
//		squadsBar.addItem(mntmFotball);
//		
//		MenuItem mntmBasketball = new MenuItem("Basketball", false, (Command) null);
//		squadsBar.addItem(mntmBasketball);
//		
//		MenuItem mntmWrestling = new MenuItem("Wrestling", false, (Command) null);
//		squadsBar.addItem(mntmWrestling);
//		
//		MenuItem mntmCompetition = new MenuItem("Competition", false, (Command) null);
//		squadsBar.addItem(mntmCompetition);
//		
//		//Media
//		MenuItem mntmMedia = new MenuItem("Media", false, mediaBar);
//		mntmMedia.setStyleName("mepo-menu-item");
//		
//		MenuItem mntmPhotos = new MenuItem("Photos", false, (Command) null);
//		mediaBar.addItem(mntmPhotos);
//		
//		MenuItem mntmImages = new MenuItem("Images", false, (Command) null);
//		mediaBar.addItem(mntmImages);
//		
//		//Coaches
//		MenuItem mntmCoaches = new MenuItem("Coaches", false, coachesBar);
//		mntmCoaches.setStyleName("mepo-menu-item");
//		
//		MenuItem mntmCassie = new MenuItem("Cassie", false, (Command) null);
//		coachesBar.addItem(mntmCassie);
//		
//		MenuItem mntmReagan = new MenuItem("Reagan", false, (Command) null);
//		coachesBar.addItem(mntmReagan);
		
//		//Menu
//		MenuBar menuBar = new MenuBar(false);
//		menuBar.setStyleName("cheerMenu");
//		menuBar.addItem(mntmSquads);
//		menuBar.addItem(mntmMedia);
//		menuBar.addItem(mntmCoaches);

//		return menuBar;
//	}
	
	public static void setContent(Widget content) {
		contentPanel.remove(1);
		contentPanel.add(content);
	}
	
	private static ClickHandler homeClickHandler = new ClickHandler() {
		@Override
		public void onClick(ClickEvent event) {
			setContent(new HomePage());
		}
	};
	
}
